<?php namespace Phpcmf\Controllers;

class Buy extends \Phpcmf\Home\Module {

    public function index() {

        $id = (int)\Phpcmf\Service::L('Input')->get('id');
        if (!$id) {
            exit($this->_msg(0, dr_lang('id参数不完整')));
        } elseif (!$this->uid) {
            $this->_msg(0, dr_lang('登录之后才能购买'));
        }

        $this->_module_init();
        $data = $this->_Show($id, null, null, 1);
        if (!$data) {
            $this->_msg(0, dr_lang('id参数不完整'));
        } elseif ($data['uid'] == $this->uid) {
            $this->_msg(0, dr_lang('不能购买自己的'));
        } elseif (\Phpcmf\Service::M('buy', MOD_DIR)->is_buy($this->uid, $id)) {
            $daoqi = \Phpcmf\Service::M()->db->table('1_'.MOD_DIR.'_buy')->where('cid', $id)->where('uid', $this->uid)->get()->getRowArray();
			if ($daoqi['endtime'] < time()) {
				
			} else {
				$this->_msg(0, dr_lang('已经购买过，无需重复购买'));
			}
			
        }

        \Phpcmf\Service::V()->assign([
            'payform' => dr_payform('my-'.MOD_DIR.'_buy-'.$id),
            'meta_title' => dr_lang('在线付款').SITE_SEOJOIN.SITE_NAME,
            'meta_keywords' => $this->get_cache('site', SITE_ID, 'config', 'SITE_KEYWORDS'),
            'meta_description' => $this->get_cache('site', SITE_ID, 'config', 'SITE_DESCRIPTION')
        ]);
        \Phpcmf\Service::V()->display('buy.html');
    }
}
